//
// Created by hugan on 2020/11/16.
//

#ifndef HUP_UTILS_PARENT_CPP_COMMONUTIL_H
#define HUP_UTILS_PARENT_CPP_COMMONUTIL_H

#include <jni.h>
#include <iostream>
#include <vector>
#include <Windows.h>

using namespace std;

class CommonUtil {
public://common
    static bool toCBool(jboolean v);

    static void printRes(const char *desc, jboolean res);

    /**
     * 求数组长度;不能用于方法的数组入参
     */
    template<class T>
    static int getLength(T &a) {
        return sizeof(a) / sizeof(a[0]);
    };

    /**
     * 触发键盘按键:先按下,后抬起;
     * SendInput例子
     * https://www.cnblogs.com/buyishi/p/10320789.html
     * SendInput
     * https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput
     * KEYBDINPUT
     * https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-keybdinput
     * Virtual-Key Codes
     * https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
     * UIPI ChangeWindowMessageFilterEx
     * https://blog.csdn.net/hellokandy/article/details/70158598
     * @param keys 按键列表
     * @return SendInput执行成功的按键指令数(等于keys长度的两倍)
     * @note 存在UIPI问题,高级权限程序前置时(如任务管理器),指令无效,但返回值仍然是成功的
     */
    static int activeKeys(vector<WORD> keys);

};

#endif //HUP_UTILS_PARENT_CPP_COMMONUTIL_H
